<template>
	<!-- 私教 -->
	<view>
		<view class="shopV" v-for="(item,key) in dataList" :key="key">
			<view class="titleV">
				<view class="leftV">
					<view class="leftTv1">{{item.shop_name}}</view>
					<view class="leftTv2">{{item.distance}}</view>
				</view>
				<view class="rightV" @click="onMapClick(item)">查看地图
					<u-icon name="arrow-right" color="#BCBBBC" size="13"></u-icon>
				</view>
			</view>
			<view class="listV">
				<scroll-view class="scrV" scroll-x="true">
					<view @tap="onItemClick(items)" class="itemV" v-for="(items,keys) in item.list" :key="keys">
						<view class="itemBg">
							<image class="avatarIv" :src="items.avatar"></image>
							<view class="nameTv">{{items.name}}</view>
							<view class="typeTv">{{items.motto}}</view>
							<view v-if="items.price" class="moneyTv">{{items.price}}起/课时</view>
							<view v-else class="moneyTv">--</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>

		<uni-popup ref="popup" type="bottom" background-color="#1F1F1F">
			<view class="popupBg">
				<view class="topV">
					<view class="titleV">
						<view @tap="onSelectClick(1)" :class="teachPos==1?'tv1':'tv1To'">擅长方向</view>
						<view @tap="onSelectClick(2)" :class="teachPos==2?'tv2':'tv2To'">门店</view>
						<view class="tv3"></view>
						<image @tap="onClseClick" class="iv" src="../../static/public/colse.svg"></image>
					</view>
					<view v-if="teachPos==1" class="kechengV">
						<view class="rightKCV">
							<scroll-view style="margin-bottom: 98rpx; height: 100%;" scroll-y="true"
								show-scrollbar="true">
								<view v-for="(data,index) in screeningShanChang" :key="index"
									:class="data.select?'rightKCVTv2To':'rightKCVTv2'"
									@tap="onSelectShanChangClick(data)">
									{{data.name}}
								</view>
							</scroll-view>
						</view>
					</view>
					<view v-if="teachPos==2" class="mendian">
						<view class="dianLeftV">
							<view class="dianLeftTv1">地区</view>
							<view style="height: 610rpx;">
								<scroll-view style="margin-bottom: 98rpx; height: 100%;" scroll-y="true"
									show-scrollbar="true">
									<view v-for="(data,index) in screeningCity" :key="index"
										:class="data.select?'dianLeftTv2To':'dianLeftTv2'"
										@tap="onSelectCityClick(data)">
										{{data.name}}
									</view>
								</scroll-view>
							</view>
						</view>
						<view class="dianRightV">
							<view class="dianRightTv1">选择门店(可多选)</view>
							<view style="height: 610rpx;">
								<scroll-view style="margin-bottom: 98rpx; height: 100%;" scroll-y="true"
									show-scrollbar="true">
									<view v-for="(data,index) in screeningMenDian" :key="index"
										:class="data.select?'dianRightTv2To':'dianRightTv2'"
										@tap="onSelectMenDianClick(data)">
										{{data.name}}
									</view>
								</scroll-view>
							</view>
						</view>
					</view>
				</view>
				<view class="bottomV">
					<view class="bt1" @tap="onResetClick">重置</view>
					<view class="bt2" @tap="onConfirmClick">确认</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		name: "teach",
		data() {
			return {
				dataList: [],
				teachPos: 1,
				screeningShanChang: [], //筛选的擅长
				screeningCity: [], //筛选的城市
				screeningMenDian: [], //筛选的门店
				selectShanChang: [], //选择的擅长
				selectCity: [], //选择的城市
				selectMenDian: [], //选择的门店
			};
		},
		created() {
			this.getTeachList()
			let that = this;
			uni.$on('Teach', function(data) {
				if (that.screeningShanChang.length == 0 && that.screeningMenDian.length == 0) {
					that.getTeachScreen()
					that.getTeachShopList("")
				} else {
					that.$refs.popup.open()
				}
			})
		},
		destroyed() {
			uni.$off('Teach')
		},
		methods: {
			onItemClick(item) {
				this.$u.route({
					url: '/pages/schedule/TeachDetails',
					params: {
						id: item.id,
					}
				})
			},
			getTeachList() { //获取私教列表

				let shanChang = [];
				this.selectShanChang.map((item, index) => {
					if (item != 0) {
						shanChang.push(item)
					}
				});

				let menDain = [];
				this.selectMenDian.map((item, index) => {
					if (item != 0) {
						menDain.push(item)
					}
				});
				this.$api.getTeachList({
					data: {
						longitude: uni.getStorageSync("user_longitude"),
						latitude: uni.getStorageSync("user_latitude"),
						shop_ids: menDain.join(","),
						level: shanChang.join(",")
					}
				}).then((res) => {
					this.dataList = res;
				}).catch((e) => {})
			},
			getTeachScreen() { //获取私教筛选
				this.$api.getTeachScreen({}).then((res) => {
					let data1 = {
						id: 0,
						name: "全部",
						select: true
					}
					let data2 = {
						id: 0,
						name: "全城",
						select: true
					}
					res.target_list.map((items, index) => {
						items.select = false;
					});
					res.city_list.map((items, index) => {
						items.select = false;
					});

					this.selectShanChang.push(0);
					this.screeningShanChang = [];
					this.screeningShanChang.push(data1);
					this.screeningShanChang.push(...res.target_list);

					this.selectCity.push(0);
					this.screeningCity = [];
					this.screeningCity.push(data2);
					this.screeningCity.push(...res.city_list);

					this.$refs.popup.open()
				}).catch((e) => {})
			},
			getTeachShopList(city) {
				this.$api.getTeachShopList({
					city_code: city
				}).then((res) => {
					let data3 = {
						id: 0,
						name: "全部",
						select: true
					}
					res.data.map((items, index) => {
						items.select = false;
					});
					this.selectMenDian.push(0);
					this.screeningMenDian = [];
					this.screeningMenDian.push(data3);
					this.screeningMenDian.push(...res.data);
				}).catch((e) => {})
			},
			onSelectClick(e) {
				this.teachPos = e;
			},
			onClseClick() {
				this.$refs.popup.close()
			},
			onSelectShanChangClick(item) {
				if (item.id == 0) { //点击了全部
					console.log("=====" + JSON.stringify(item))
					this.screeningShanChang.map((items, index) => {
						items.select = false;
					});
					let isSele = item.select;
					item.select = !isSele;
				} else {
					console.log("==+++==" + JSON.stringify(item))
					this.screeningShanChang.map((items, index) => {
						if (items.id == 0) {
							items.select = false;
						}
					});

					let isSele = item.select;
					item.select = !isSele;
				}
			},
			onSelectCityClick(item) {
				if (item.id == 0) { //点击了全部
					this.screeningCity.map((items, index) => {
						items.select = false;
					});
					let isSele = item.select;
					item.select = !isSele;
				} else {
					this.screeningCity.map((items, index) => {
						if (items.id == 0) {
							items.select = false;
						}
					});

					let isSele = item.select;
					item.select = !isSele;
				}
				let cityS = [];
				this.screeningCity.map((items, index) => {
					if (items.select && items.id != 0) {
						cityS.push(items.id)
					}
				});
				this.getTeachShopList(cityS.join(","));
			},
			onSelectMenDianClick(item) {
				if (item.id == 0) { //点击了全部
					this.screeningMenDian.map((items, index) => {
						items.select = false;
					});
					let isSele = item.select;
					item.select = !isSele;
				} else {
					this.screeningMenDian.map((items, index) => {
						if (items.id == 0) {
							items.select = false;
						}
					});

					let isSele = item.select;
					item.select = !isSele;
				}
			},
			onResetClick() { //重置
				this.selectShanChang = []
				this.screeningShanChang.map((items, index) => {
					if (items.id == 0) {
						items.select = true;
						this.selectShanChang.push(items.id)
					} else {
						items.select = false;
					}
				});

				this.selectMenDian = []
				this.screeningMenDian.map((items, index) => {
					if (items.id == 0) {
						items.select = true;
						this.selectMenDian.push(items.id)
					} else {
						items.select = false;
					}
				});

				this.$refs.popup.close()
				this.getTeachList()
			},
			onConfirmClick() { //确定
				this.selectShanChang = []
				this.selectCity = []
				this.selectMenDian = []

				this.screeningShanChang.map((items, index) => {
					if (items.select) {
						this.selectShanChang.push(items.id);
					}
				});
				this.screeningCity.map((items, index) => {
					if (items.select) {
						this.selectCity.push(items.id);
					}
				});
				this.screeningMenDian.map((items, index) => {
					if (items.select) {
						this.selectMenDian.push(items.id);
					}
				});

				this.$refs.popup.close()
				this.getTeachList()
			},
			onMapClick(item){
				uni.authorize({
					scope: 'scope.userLocation',
					success() {
						uni.openLocation({
							longitude: parseFloat(item.longitude),
							latitude: parseFloat(item.latitude),
							name:item.shop_name,//位置名
							address:"",//详细地址
							success: function (res) {
								console.log('位置名称：' + res.name);
								console.log('详细地址：' + res.address);
								console.log('纬度：' + res.latitude);
								console.log('经度：' + res.longitude);
							},
							fail(res){
								console.log("====="+JSON.stringify(res))
							}
						});
					},
					fail() {
						uni.showModal({
							title: '未打开小程序定位',
							content: '找不到您的位置，请开启定位',
							confirmText: '开启定位',
							showCancel: false,
							success: (res) => {
								if (res.confirm) {
									uni.openSetting(); // 打开地图权限设置
								}
							}
						});
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.shopV {
		height: 435rpx;
		background: #E6A5B4;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		box-sizing: border-box;
		margin-top: 30rpx;

		.titleV {
			display: flex;
			padding-left: 30rpx;
			padding-right: 30rpx;
			align-items: center;
			justify-content: space-between;

			.leftV {
				display: flex;
				align-items: center;
				justify-content: center;

				.leftTv1 {
					color: #E8E8E8;
					font-size: 32rpx;
				}

				.leftTv2 {
					font-size: 28rpx;
					color: #FFFFFF;
					margin-left: 30rpx;
				}
			}

			.rightV {
				display: flex;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}

		.listV {
			padding-left: 30rpx;
			margin-top: 30rpx;

			.scrV {
				width: 100%;
				white-space: nowrap;
				vertical-align: middle;
				overflow: hidden;
				height: 300rpx;

				.itemV {
					width: 210rpx;
					height: 300rpx;
					background: #eacccc;
					margin-right: 15rpx;
					display: inline-block;
					flex-direction: column;
					align-items: center;


					.itemBg {
						width: 210rpx;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;

						.avatarIv {
							width: 100rpx;
							height: 100rpx;
							border-radius: 50%;
							margin-top: 30rpx;
						}

						.nameTv {
							font-size: 30rpx;
							color: #E9869D;
							margin-top: 10rpx;
						}

						.typeTv {
							margin-top: 10rpx;
							background: #C37F8F;
							border-radius: 10rpx 0rpx 10rpx 0rpx;
							color: #FFFFFF;
							font-size: 22rpx;
							padding-left: 18rpx;
							padding-right: 18rpx;
							padding-top: 1rpx;
							padding-bottom: 1rpx;
							margin-left: 20rpx;
							margin-right: 20rpx;
							display: block;
							white-space: nowrap;
							text-overflow: ellipsis;
							overflow: hidden;
							width: fit-content;
							max-width: 180rpx;
							box-sizing: border-box;
						}

						.moneyTv {
							margin-top: 18rpx;
							font-size: 22rpx;
							color: #E9869D;
						}
					}
				}
			}
		}
	}

	.popupBg {
		height: 900rpx;

		.topV {
			height: 802rpx;

			.titleV {
				display: flex;
				margin-top: 30rpx;
				margin-left: 30rpx;
				margin-right: 30rpx;

				.tv1 {
					color: #CEF743;
					font-size: 32rpx;
					padding-bottom: 15rpx;
					box-sizing: border-box;
					border-bottom: 5rpx solid #CEF743;
					margin-right: 30rpx;
				}

				.tv1To {
					color: #FFFFFF;
					font-size: 32rpx;
					padding-bottom: 15rpx;
					box-sizing: border-box;
					border-bottom: 5rpx solid #00000000;
					margin-right: 30rpx;
				}

				.tv2 {
					color: #CEF743;
					font-size: 32rpx;
					padding-bottom: 15rpx;
					box-sizing: border-box;
					border-bottom: 5rpx solid #CEF743;
				}

				.tv2To {
					color: #FFFFFF;
					font-size: 32rpx;
					padding-bottom: 15rpx;
					box-sizing: border-box;
					border-bottom: 5rpx solid #00000000;
				}

				.tv3 {
					flex: 1;
				}

				.iv {
					width: 42rpx;
					height: 42rpx;
				}
			}

			.kechengV {
				display: flex;
				height: 725rpx;
				margin-top: 30rpx;
				box-sizing: border-box;

				.rightKCV {
					flex: 1;

					.rightKCVTv2 {
						margin-left: 30rpx;
						margin-right: 30rpx;
						height: 60rpx;
						background: #3D3F3E;
						border-radius: 10rpx;
						margin-bottom: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						color: #939393;
						border: 1rpx solid #00000000;
					}

					.rightKCVTv2To {
						margin-left: 30rpx;
						margin-right: 30rpx;
						height: 60rpx;
						background: rgba(206, 247, 67, 0.2);
						border-radius: 10rpx;
						margin-bottom: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						color: #CEF743;
						border: 1rpx solid #CEF743;
					}
				}
			}

			.mendian {
				display: flex;
				height: 725rpx;
				margin-top: 30rpx;
				box-sizing: border-box;

				.dianLeftV {
					flex: 3;
					height: 725rpx;

					.dianLeftTv1 {
						display: flex;
						align-items: center;
						justify-content: center;
						color: #fff;
						font-size: 32rpx;
						padding-top: 30rpx;
						padding-bottom: 30rpx;
						box-sizing: border-box;
					}

					.dianLeftTv2 {
						margin-left: 30rpx;
						margin-right: 30rpx;
						height: 60rpx;
						background: #3D3F3E;
						border-radius: 10rpx;
						margin-bottom: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						color: #939393;
						border: 1rpx solid #00000000;
						overflow: hidden;
						/*溢出的部分隐藏*/
						white-space: nowrap;
						/*文本不换行*/
						text-overflow: ellipsis;
					}

					.dianLeftTv2To {
						margin-left: 30rpx;
						margin-right: 30rpx;
						height: 60rpx;
						background: rgba(206, 247, 67, 0.2);
						border-radius: 10rpx;
						margin-bottom: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						color: #CEF743;
						border: 1rpx solid #CEF743;
						overflow: hidden;
						/*溢出的部分隐藏*/
						white-space: nowrap;
						/*文本不换行*/
						text-overflow: ellipsis;
					}


				}

				.dianRightV {
					flex: 7;

					.dianRightTv1 {
						display: flex;
						align-items: center;
						justify-content: center;
						color: #fff;
						font-size: 32rpx;
						padding-top: 30rpx;
						padding-bottom: 30rpx;
						box-sizing: border-box;
					}

					.dianRightTv2 {
						margin-left: 30rpx;
						margin-right: 30rpx;
						height: 60rpx;
						background: #3D3F3E;
						border-radius: 10rpx;
						margin-bottom: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						color: #939393;
						border: 1rpx solid #00000000;
					}

					.dianRightTv2To {
						margin-left: 30rpx;
						margin-right: 30rpx;
						height: 60rpx;
						background: rgba(206, 247, 67, 0.2);
						border-radius: 10rpx;
						margin-bottom: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						color: #CEF743;
						border: 1rpx solid #CEF743;
					}


				}
			}
		}


		.bottomV {
			display: flex;
			height: 98rpx;

			.bt1 {
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
				background: #3D3F3E;
				color: #939393;
				font-size: 32rpx;
			}

			.bt2 {
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
				background: #CEF743;
				color: #333333;
				font-size: 32rpx;
			}
		}
	}
</style>
